<template>
  <el-container>
    <el-header>欢迎你，普通管理员：{{ userInfo.username }}
      <el-button size="mini" type="primary" @click="userOut">退出</el-button>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <el-row class="tac">
          <el-menu router :default-active="$route.path" class="el-menu-vertical-demo" background-color="#545c64" text-color="#fff"
            active-text-color="#ffd04b">
            <template v-for="(item, index) in means">
              <el-submenu v-if="!item.children" :key="item._id" :index="item.path || index + ''">
                <template slot="title">
                  <i :class="item.icon"></i>
                  <span>{{ item.title }}</span>
                </template>
              </el-submenu>
              <el-submenu v-else :key="item._id" :index="item.path || index + ''">
                <template slot="title">
                  <i :class="item.icon"></i>
                  <span>{{ item.title }}</span>
                </template>
                <el-menu-item-group>
                  <el-menu-item v-for="(obj, ind) in item.children" :key="obj._id"
                    :index="'/main/'+ obj.path || ind + ''">
                    {{ obj.title }}
                  </el-menu-item>
                </el-menu-item-group>
              </el-submenu>
            </template>
          </el-menu>
        </el-row>
      </el-aside>
      <el-main><router-view></router-view></el-main>
    </el-container>
  </el-container>
</template>

<script>
import request from '@/utils/request';
export default {
  data() {
    return {
      userInfo: {},
      means: []
    }
  },
  mounted() {
    this.getUseInfo();
    this.getMeans()
  },
  methods: {
    getUseInfo() {
      request.get("/users/getUserInfo", {
        headers: {
          Authorization: localStorage.token,
        }
      })
        .then(res => {
          console.log(res);
          if (res.data.code === 1) {
            this.userInfo = res.data.data
          }
        })
    },
    getMeans() {

      request.get("/users/getMenus", {
        headers: {
          Authorization: localStorage.token,
        }
      })
        .then(res => {
          console.log(res);
          if (res.data.code === 1) {
            this.means = res.data.data;
            console.log(this.means);
          }
        })
    },
    userOut() {
      this.$confirm('此操作将退出当前用户, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        localStorage.clear();
        this.$router.replace('/login');
        this.$message({
          type: 'success',
          message: '退出成功!'

        });

      })
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    }
  }
}
</script>

<style lang="scss" scoped>
.el-container {
  height: 100vh;
}

.el-header,
.el-footer {
  background-color: #010624;
  color: rgb(252, 250, 250);
  text-align: right;
  line-height: 60px;
  font-size: 15px;
}

.el-aside {
  background-color: #010624;
  color: rgb(252, 250, 250);
  text-align: center;
  line-height: 200px;
  font-size: 15px;
}

.el-main {
  background-color: #E9EEF3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body>.el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>